package com.lagou.sort;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

// 输出的k 定义为 LongWritable，是为了方便排序（如果数字较长可定义为 LongWritable）
public class SortMapper extends Mapper<LongWritable, Text, LongWritable, NullWritable> {

    private final LongWritable k = new LongWritable();
    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        int num = Integer.parseInt(value.toString());
        k.set(num);
        context.write(k, NullWritable.get());
    }
}
